<template>
  <div class="login">
    <!-- 导航 -->
    <van-nav-bar
      left-arrow
      title="登录"
      fixed
      style="background-color: #3f51b5"
    />
    <div class="test">
      <!-- 表单 -->
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="nameRules"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="pwdRules"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >登录</van-button
          >
        </div>
      </van-form>
    </div>
    <!-- 环形数据 -->
    <div class="circle">
      <div>
        <van-circle
          v-model="currentRate"
          :rate="74"
          :speed="30"
          :text="text"
          layer-color="#eeecec"
        />
        <p>同城使用率</p>
      </div>
      <div>
        <van-circle
          v-model="currentRate1"
          :rate="97"
          :speed="30"
          :text="text1"
          color="#EE0A24"
          layer-color="#eeecec"
        />
        <p>好评率</p>
      </div>
      <div>
        <van-circle
          v-model="currentRate2"
          :rate="100"
          :speed="30"
          :text="text2"
          color="#7232DD"
          layer-color="#eeecec"
        />
        <p>回头使用率</p>
      </div>
    </div>
    <div class="words">
      <p>用户名：13000000000</p>
      <p>密码：123456</p>
    </div>
  </div>
</template>

<script>
import { getLoginUser } from "@/api/login";
export default {
  data() {
    return {
      currentRate: 0,
      currentRate1: 0,
      currentRate2: 0,
      username: "",
      password: "",
      nameRules: [
        {
          required: true,
          message: "用户名不能为空",
          trigger: "onBlur",
        },
        {
          validator: (value) => {
            if (this.username == 13000000000) {
              this.value = true;
              return value;
            } else {
              this.value = false;
              return false;
            }
          },
          message: "用户名不存在",
          trigger: "onBlur",
        },
      ],
      pwdRules: [
        {
          required: true,
          message: "密码不能为空",
          trigger: "onBlur",
        },
        {
          validator: (value) => {
            if (this.password == 123456) {
              this.value = true;
              return value;
            } else {
              this.value = false;
              return false;
            }
          },
          message: "密码错误",
          trigger: "onBlur",
        },
      ],
    };
  },
  created() {
    this.loadUserInfo();
  },
  computed: {
    text() {
      return this.currentRate.toFixed(0) + "%";
    },
    text1() {
      return this.currentRate1.toFixed(0) + "%";
    },
    text2() {
      return this.currentRate2.toFixed(0) + "%";
    },
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      this.$router.push({ path: "/home", replace: true });
    },
    async loadUserInfo() {
      const { data } = await getLoginUser();
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  height: 100vh;
  display: flex;
  justify-content: center;
  background-image: url("https://img0.baidu.com/it/u=2537291591,2027983916&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=710");
  .van-nav-bar {
    /deep/.van-icon-arrow-left:before {
      color: white;
    }
    /deep/.van-nav-bar__title {
      color: white;
    }
  }
  .test {
    width: 700px;
    height: 600px;
    margin-top: 200px;
    border-radius: 30px;
    display: flex;
    justify-content: center;
    background-color: #3f51b5;
    .van-form {
      margin-top: 90px;
      .van-button {
        top: 70px;
        color: #3f51b5;
        background-color: #eeecec;
      }
    }
  }
  .circle {
    position: fixed;
    display: flex;
    justify-content: space-between;
    bottom: 0;
    width: 690px;
    height: 450px;
    div {
      text-align: center;
      font-size: 32px;
      font-weight: 900;
    }
  }
  .words{
    position: fixed;
    bottom: 0;
    text-align: center;
    font-size: 12px;
  }
}
</style>